package com.sdry.web.controller.jyy;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sdry.model.jyy.PlanDetail;
import com.sdry.model.jyy.PlanDetailExample;
import com.sdry.model.jyy.PlanDetailExample.Criteria;
import com.sdry.service.jyy.PlanDetailServise;
import com.sdry.utils.ResponseUtil;


/**
 * 
 * @ClassName:    PlanController   
 * @Description:  生产计划
 * @Author:       jyy
 * @CreateDate:   2018年9月25日 下午2:45:44   
 * @Version:      v1.0
 */
@Controller
@RequestMapping("planDetail")
public class PlanDetailController {
	
	@Resource
	private PlanDetailServise planDetailServise;
	
	
	/**
	 * 查询生产计划列表
	 * @param response
	 * @throws Exception 
	 */
	@RequestMapping("planDetailList")
	public void planDetailList(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(value = "limit",required = false)int limit,
			@RequestParam(value = "page",required = false)int page,
			PlanDetail planDetail) throws Exception{
		PageHelper.startPage(page, limit);
		
		PlanDetailExample example = new PlanDetailExample();
		Criteria createCriteria = example.createCriteria();
		if(planDetail.getRemark4() != null && planDetail.getRemark4() != "") {
    		createCriteria.andRemark4EqualTo(planDetail.getRemark4());
    	}
		 
		List<PlanDetail> list = planDetailServise.selectByExample(example);
		
		PageInfo<PlanDetail> info = new PageInfo<PlanDetail>(list);
    	
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code", 0);
        jsonObject.put("msg", "");
        jsonObject.put("count", info.getTotal());
        jsonObject.put("data", info.getList());
        ResponseUtil.write(response, jsonObject);
	}
	
	/**
	 * 查询生产计划列表
	 * @param response
	 * @throws Exception 
	 */
	@RequestMapping("/getList")
	public void getList(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(value = "limit",required = false)int limit,
			@RequestParam(value = "page",required = false)int page,
			PlanDetail planDetail) throws Exception{
		PageHelper.startPage(page, limit);
		
		PlanDetailExample example = new PlanDetailExample();
		Criteria createCriteria = example.createCriteria();
		if(planDetail.getRemark4() != null && planDetail.getRemark4() != "") {
			createCriteria.andRemark4EqualTo(planDetail.getRemark4());
		}
		
		List<PlanDetail> list = planDetailServise.getList(example);
		
		PageInfo<PlanDetail> info = new PageInfo<PlanDetail>(list);
		
		JSONObject jsonObject=new JSONObject();
		jsonObject.put("code", 0);
		jsonObject.put("msg", "");
		jsonObject.put("count", info.getTotal());
		jsonObject.put("data", info.getList());
		ResponseUtil.write(response, jsonObject);
	}
	
}
